#include "LUA_Font.h"

int createFont(lua_State* L){
	const char* fontfile = lua_tostring(L, -1);

	OGLFT::MonochromeTexture* monochrome = new OGLFT::MonochromeTexture(fontfile, 14);

	if ( monochrome == 0 || !monochrome->isValid() ) {
	     LUAERROR("could not load font file");
	  }
	monochrome->setForegroundColor(1.,1.,1.);

	OGLFT::MonochromeTexture** font = (OGLFT::MonochromeTexture**)createClass(L, sizeof(OGLFT::MonochromeTexture*), "Data.Font");
	*font = monochrome;

	return 1;
}

int drawFont(lua_State* L){
	int x = lua_tointeger(L, -3);
	int y = lua_tointeger(L, -2);
	const char* text = lua_tostring(L, -1);

	OGLFT::MonochromeTexture** font = (OGLFT::MonochromeTexture**)getClass(L, "Data.Font");
	OGLFT::MonochromeTexture* monochrome = *font;
	monochrome->draw(x,y, text);

	return 0;
}

int setSizeFont(lua_State* L){
	int size = lua_tointeger(L,-1);

	OGLFT::MonochromeTexture** font = (OGLFT::MonochromeTexture**)getClass(L, "Data.Font");
	OGLFT::MonochromeTexture* monochrome = *font;

	monochrome->setPointSize(size);

	return 0;
}

int setFrontColorFont(lua_State* L){
	double R = lua_tonumber(L, -4);
	double G = lua_tonumber(L, -3);
	double B = lua_tonumber(L, -2);
	double A = lua_tonumber(L, -1);

	OGLFT::MonochromeTexture** font = (OGLFT::MonochromeTexture**)getClass(L, "Data.Font");
	OGLFT::MonochromeTexture* monochrome = *font;

	monochrome->setForegroundColor(R,G,B,A);

	return 0;
}

int setBackColorFont(lua_State* L){
	double R = lua_tonumber(L, -4);
	double G = lua_tonumber(L, -3);
	double B = lua_tonumber(L, -2);
	double A = lua_tonumber(L, -1);

	OGLFT::MonochromeTexture** font = (OGLFT::MonochromeTexture**)getClass(L, "Data.Font");
	OGLFT::MonochromeTexture* monochrome = *font;

	monochrome->setBackgroundColor(R,G,B,A);

	return 0;
}

int destroyFont(lua_State* L){
	OGLFT::MonochromeTexture** font = (OGLFT::MonochromeTexture**)getClass(L, "Data.Font");
	OGLFT::MonochromeTexture* monochrome = *font;

	delete monochrome;
	lua_pushnil(L);

	return 1;
}
